package jmine.tec.hydra.web.pages.especificacao;

import jmine.tec.hydra.web.pages.especificacao.ConsultaIntegracaoEspecificacao.HydraSpecificationRowData;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;

/**
 * Panel que exibe o detalhe de um {@link HydraSpecificationRowData}.
 * 
 * @author Renan Kuroki
 * @created 04/01/2011
 */
public class ModalPanelDetalheEspecificacao extends Panel {

    private HydraSpecificationRowData specRowData;

    /**
     * Construtor
     * 
     * @param id id do componente ModalWindow
     * @param specRowData HydraSpecificationRowData
     */
    public ModalPanelDetalheEspecificacao(String id, HydraSpecificationRowData specRowData) {
        super(id);
        this.specRowData = specRowData;
        this.generateComponents();
    }

    /**
     * Gera os componentes utilizados pelo modal panelz
     */
    private void generateComponents() {
        this.add(new Label("sistema", new PropertyModel<String>(this.specRowData, "specification.system")));
        this.add(new Label("acao", new PropertyModel<String>(this.specRowData, "specification.action")));
        this.add(new Label("status", new PropertyModel<String>(this.specRowData, "status")));
        this.add(new Label("emissor", new PropertyModel<String>(this.specRowData, "emissor")));
        this.add(new Label("descricaoEmissor", new PropertyModel<String>(this.specRowData, "descricaoEmissor")));

        WebMarkupContainer containerCodificacao = new WebMarkupContainer("containerCodificacao");
        containerCodificacao.add(new Label("codificacao", new PropertyModel<String>(this.specRowData,
                "specification.encodeScript.mnemonico")));
        containerCodificacao.add(new TextArea<String>("detalheCodificacao", new PropertyModel<String>(this.specRowData,
                "specification.encodeScript.body")));
        if (this.specRowData.getSpecification().getEncodeScript() == null) {
            containerCodificacao.setVisible(false);
        }
        this.add(containerCodificacao);

        WebMarkupContainer containerDecodificacao = new WebMarkupContainer("containerDecodificacao");
        containerDecodificacao.add(new Label("decodificacao", new PropertyModel<String>(this.specRowData,
                "specification.decodeScript.mnemonico")));
        containerDecodificacao.add(new TextArea<String>("detalheDecodificacao", new PropertyModel<String>(this.specRowData,
                "specification.decodeScript.body")));
        if (this.specRowData.getSpecification().getDecodeScript() == null) {
            containerDecodificacao.setVisible(false);
        }
        this.add(containerDecodificacao);

        WebMarkupContainer containerModelo = new WebMarkupContainer("containerModelo");
        containerModelo.add(new Label("modelo", new PropertyModel<String>(this.specRowData, "specification.template.mnemonico")));
        containerModelo.add(new TextArea<String>("detalheModelo",
                new PropertyModel<String>(this.specRowData, "specification.template.body")));
        if (this.specRowData.getSpecification().getTemplate() == null) {
            containerModelo.setVisible(false);
        }
        this.add(containerModelo);
    }
}